/**
 * 图片按顺序加载
 * @param {*} $container 容器
 * @param {*} list 文件数组
 * @param {*} index 文件索引
 * @returns null
 */
export const loopImgLoadInOrder = ($container = document.body, list: any, index = 0) => {
  if (index >= list.length) return
  const img = list[index]
  // 图片src赋值
  img.url = img['data-url']
  // 图片dom
  const $img = $container.querySelector(`.image-${img.uid} img`)
  if ($img) {
    $img.addEventListener('load', () => {
      loopImgLoadInOrder($container, list, index + 1)
    })
    $img.addEventListener('error', () => {
      loopImgLoadInOrder($container, list, index + 1)
    })
  } else {
    loopImgLoadInOrder($container, list, index + 1)
  }
}
